<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="./lib/vue-2.4.0.js"></script>
    <!-- 1. 安装 vue-router 路由模块 -->
    <script src="./lib/vue-router-3.0.1.js"></script>
    <style>
      .router-link-active,
      .myactive {
        color: red;
        font-weight: 800;
        font-style: italic;
        font-size: 80px;
        text-decoration: underline;
        background-color: green;
      }

      .v-enter,
      .v-leave-to {
        opacity: 0;
        transform: translateX(140px);
      }

      .v-enter-active,
      .v-leave-active {
        transition: all 0.5s ease;
      }
    </style>
  </head>

  <body>
    <div id="app">
      <!-- router-link 默认渲染为一个a 标签 -->
      <router-link to="/login" tag="span">登录</router-link>
      <router-link to="/register">注册</router-link>

      <transition mode="out-in">
        <router-view></router-view>
      </transition>
    </div>

    <script>
      // 组件的模板对象
      var login = {
        template: "<h1>登录组件</h1>"
      };

      var register = {
        template: "<h1>注册组件</h1>"
      };
      var routerObj = new VueRouter({
        routes: [
          // 路由匹配规则
          // { path: '/', component: login },
          { path: "/", redirect: "/login" }, // 这里的 redirect 和 Node 中的 redirect 完全是两码事
          { path: "/login", component: login },
          { path: "/register", component: register }
        ],
        linkActiveClass: "myactive"
      });
      var vm = new Vue({
        el: "#app",
        data: {},
        methods: {},
        router: routerObj // 将路由规则对象，注册到 vm 实例上，用来监听 URL 地址的变化，然后展示对应的组件
      });
    </script>
  </body>
</html>
